<?php
	Zend_loader::loadClass("OrganismAttribute");
	Zend_loader::loadClass("Organisms");
	Zend_Loader::loadClass("AuthUtility");
	class SizeUtility{
		
		public function AddOrganismSizes($size){
			$auth = BaseAuth::getInstance();
			$orgs = new Organisms();
			$orgs->load();
			foreach($orgs as $org){
				$organism = $org->toArray();
				
				$obj = new OrganismAttribute();
				$size_flag = $obj->loadWhere("size_code='".$size->size_code."' AND organism_id = ".$organism['id']);
				if ($size_flag) {
					//do not add attributes if existing
				} else {
					$obj->organism_id   = $organism['id'];
					$obj->size_code	    = $size->size_code;
					$obj->date_created	=	date("Y-m-d H:i:s");
					$obj->created_by	=	$auth->id;
					$obj->save();
					$obj->organism_attribute_id   = $obj->id;
					$obj->save();					
				}
			}
		}
		public function CheckOrganismAttributes($size){
			$query = new QueryCreator();
			$query->addSelect(" count(*) as cnt");
			$query->addFrom(OrganismAttribute::_tablename);
			$query->addWhere(" size_code='".$size['size_code']."'");
			
			$db = DBCon::instance();
			$temp = $db->executeQuery($query->createSQL());
			$result = $temp[0]['cnt'];
			return $result;
		}
	}
?>